<!-- title: {{ doctype }} -->
<!-- add-breadcrumbs -->

{% from "templates/autodoc/macros.html" import automodule, version,
  source_link, doctype_link %}
{% set doc = frappe.get_doc("DocType", doctype) %}
{% set controller = autodoc.get_controller(doctype) %}

<h1>{{ doctype }}</h1>
<div class="dev-header">
{{ version(doctype) }}
{{ source_link(app, app.name + "/" + scrub(doc.module)
  + "/doctype/" + scrub(doctype), True) }}
</div>

{% if doc.issingle %}<span class="label label-info">Single</span>{% endif %}
{% if doc.istable %}<span class="label label-info">Child Table</span>{% endif %}

{% if not doc.issingle %}
    <p><b>Table Name:</b> <code>tab{{ doctype }}</code></p>
{% endif %}

{{ doc.description or "" }}

<h3>Fields</h3>

<table class="table table-bordered docfields">
    <thead>
        <tr>
            <th style="width: 5%">Sr</th>
            <th style="width: 25%">Fieldname</th>
            <th style="width: 20%">Type</th>
            <th style="width: 25%">Label</th>
            <th style="width: 25%">Options</th>
        </tr>
    </thead>
    <tbody>
        {% for df in doc.fields %}
        <tr {% if df.fieldtype=="Section Break" %}class="info"{% endif %}>
            <td>{{ loop.index }}</td>
            <td {% if df.reqd %}class="danger" title="Mandatory"{% endif %}><code>{{ df.fieldname }}</code></td>
            <td {% if df.fieldtype=="Column Break" %}class="info"{% endif %}>
                {{ df.fieldtype }}</td>
            <td {% if df.hidden %}class="text-muted" title="Hidden"{% endif %}>
                {{ df.label or "" }}
                {% if df.description %}<p class="text-muted small">
                    {{ df.description }}</p>{% endif %}
            </td>
            <td>{% if df.options and df.fieldtype not in ("HTML") %}
                {% if df.fieldtype in ("Table", "Link") %}
                {{ doctype_link(app, df.options) }}
                {% else %}<pre>{{ df.options }}</pre>{% endif %}
            {% endif %}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>

{% if not doc.istable %}
    <hr>
    <h3>Controller</h3>
    <h4>{{ controller.__module__ }}</h4>

    {{ automodule(controller.__module__) }}
    {% set parents = frappe.get_list("DocField",
        filters = {"options": doctype, "fieldtype": "Link"}, fields = ["distinct parent"], order_by="parent asc") %}
    {% if parents %}
        <h4>Linked In:</h4>
        <ul>
        {% for parent in parents %}
			{% if get_doctype_app(parent.parent)==app.name %}
            <li>{{ doctype_link(app, parent.parent) }}</li>
			{% endif %}
        {% endfor %}
        </ul>
    {% endif %}
{% else %}
    {% set parents = frappe.get_list("DocField",
        filters = {"options": doctype, "fieldtype": "Table"}, fields = ["distinct parent"], order_by="parent asc") %}
    {% if parents %}
    <h4>Child Table Of</h4>
    <ul>
    {% for parent in parents %}
        <li>{{ doctype_link(app, parent.parent) }}</li>
    {% endfor %}
    </ul>
    {% endif %}
{% endif %}

<!-- autodoc -->
<!-- jinja -->
<!-- static -->
